home *** CD-ROM | disk | FTP | other *** search
- Path: pop.gnn.com!HoangTQ
- From: Tuyen Hoang <HoangTQ@gnn.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Need Help With CSC Homework
- Date: Sat, 16 Mar 1996 22:33:58
- Organization: GNN
- Message-ID: <4ig16m$h3p@news-e2c.gnn.com>
- References: <4g0qq4$o0@news.nevada.edu>
- NNTP-Posting-Host: www-29-26.gnn.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset="us-ascii"
- X-GNN-NewsServer-Posting-Date: 17 Mar 1996 03:33:42 GMT
- X-Mailer: GNNmessenger 1.2
-
-
- In article <4g0qq4$o0@news.nevada.edu> Troy Kessler
- wrote:
-
- >I am a computer student at UNLV. My assignment is to create a roman
- >calculator with a roman class. My professor wants me to overload
- > >>,<<,+,-,/, and *. I am having a problem. I am using Borland Turbo C++
- >for DOS. It says expected ) on line 88 of pfun.cpp. This is the
- >DecimalToRoman function. (the first line) I will post the list of
- >pmain.cpp pfun.cpp p.h. Please help me with my error. E-mail prefered.
- >
- > Thank You Very Much
- >Troy 3.14159265358979323846264338327950288.....
- Kessler
-
-
- Did you only have one error message?
- I recompile your code-without modification- with Borland Turbo C v. 1.01 and
- get five(5) error, all of them complain about an undefined object name
- 'answerr' in the function DecimalToRoman(), and a warning in main() that says
- the variable answerr is never used. Do you got some things like mine?
- You might want to look at my comment in the file pfun.c
-
- There are serious problems in your algorithm, too.
- You use an char array[21] for store the Roman number, so the greatest number
- is 20,000(20 letters M). How about the next one? 19,999? No, it's 19,500(19
- letters M and 1 for D)those numbers from 19,501 to 19,999 are *out* of
- your hand. There are more, 19,100(19 letters M and 1 for C) is ok, but those
- numbers from 19,101 to 19,499 are all gone. I don't have the patient to
- count all of them, but at least, I do know the problem begins at 9,888(MMM MMM
- MMM DCCC LXXX VIII : 21 letters). Surprise?
-
- The second problem is that there are NO Roman number IIII or VIIII as you try
- to implement, all I know is that number four is IV and number 9 is IX, etc.
- Suppose that your implement is acceptable, so you jump in to trouble at
- 6,999(MMM MMM DCCCC LXXXX VIIII : 21 letter) much earlier than the ancient
- Romans did.
-
- Increase the value of MAXLENGTH won't solve this problem, the correct solution
- is using dynamic allocation: allocate the char* after calculate it length at
- run time instead of using static char[MAX].
-
- If you want a hasty solution, I have it handy: the value range for type
- unsigned int is from 0 to 65,xxx(for PC), therefore for your Roman number's
- safety, you should set MAXLENGTH to 65+15+1 = 81. If you want to use long
- instead, you should increase MAXLENGTH accordingly.
-
- I don't know if you have time to make it up again.
-
- So good luck.
-
- Hoang Tuyen Q.
- HoangTQ@gnn.com
-
-